import PureUserInfo from '../components/user-info';
import * as UserAction from 'actions/user';
import { getFetchStatus } from 'actions/util';
import { Modal } from 'antd';
import * as ReactRedux from 'react-redux';
import * as React from 'react';

const mapStateToProps = (state) => {
  return {
    user: state.userById
  };
};

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    initFetch() {
      return dispatch(UserAction.getUserInfo(ownProps.email))
        .then(({ payload: user }) => {
          if (!user) {
            Modal.error({
              title: '该用户不存在'
            });
          }
        });
    }
  };
};

class UserInfo extends React.Component {
  componentDidMount() {
    this.props.initFetch();
  }

  render() {
    return <PureUserInfo {...this.props}/>;
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(UserInfo);
